package com.app.aipass.utils;

import android.content.Context;
import android.content.SharedPreferences;


public class SpUtils {

    /**
     * 向首选项中存储数据(仅限于String,int,boolean三种数据类型)
     *
     * @param key
     * @param value
     */
    public static void put(Context context,String key, Object value) {
        SharedPreferences sp = context.getSharedPreferences("user", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        if (value instanceof String) {
            editor.putString(key, (String) value);
        } else if (value instanceof Integer) {
            editor.putInt(key, (Integer) value);
        } else if (value instanceof Boolean) {
            editor.putBoolean(key, (Boolean) value);
        }
        editor.apply();
    }

    public static String get(Context context,String key) {
        SharedPreferences sp = context.getSharedPreferences("user", Context.MODE_PRIVATE);
        return sp.getString(key, "");
    }

    public static int getInt(Context context,String key) {
        SharedPreferences sp = context.getSharedPreferences("user", Context.MODE_PRIVATE);
        return sp.getInt(key, 9);
    }
}
